﻿Public Class frmLogin

    Public login_state As Boolean = False

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.login_state = False
        Me.Close()
    End Sub

    Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
        If (Me.cbUser.Text = "甲班01") And (Me.txtPWD.Text = "111") Then
            If (Me.cbUser.Text <> username) Then
                If MsgBox("确认要进行换班登录？", MsgBoxStyle.YesNo, MsgBoxTitle) = MsgBoxResult.Yes Then
                    Me.login_state = True
                    saveClassCode()
                    Me.Close()
                End If
            Else
                classname = Me.cbclass.Text
                Me.login_state = True
                Me.Close()
            End If
            
        ElseIf ((Me.cbUser.Text = "乙班01") And (Me.txtPWD.Text = "222")) Then
            If (Me.cbUser.Text <> username) Then
                If MsgBox("确认要进行换班登录？", MsgBoxStyle.YesNo, MsgBoxTitle) = MsgBoxResult.Yes Then
                    Me.login_state = True
                    saveClassCode()
                    Me.Close()
                End If
            Else
                classname = Me.cbclass.Text
                Me.login_state = True
                Me.Close()
            End If
        ElseIf ((Me.cbUser.Text = "丙班01") And (Me.txtPWD.Text = "333")) Then
            If (Me.cbUser.Text <> username) Then
                If MsgBox("确认要进行换班登录？", MsgBoxStyle.YesNo, MsgBoxTitle) = MsgBoxResult.Yes Then
                    Me.login_state = True
                    saveClassCode()
                    Me.Close()
                End If
            Else
                classname = Me.cbclass.Text
                Me.login_state = True
                Me.Close()
            End If
        Else
            MsgBox("密码错误")
        End If

    End Sub

    Private Sub cbUser_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbUser.SelectedIndexChanged
        Me.cbclass.SelectedIndex = Me.cbUser.SelectedIndex
        Me.txtPWD.Focus()
    End Sub

    Private Sub txtPWD_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPWD.GotFocus
        Me.btnConfirm.Focus()
        Dim frm As New FrmKey
        frm.ShowDialog()
        Me.txtPWD.Text = frm.M_PassWord
    End Sub

    Private Sub saveClassCode()
        Dim funName As String = "saveClassCode"
        classcode = Format(Now, "yyyyMMdd").ToString & "-" & CStr(Me.cbclass.SelectedIndex + 1)
        username = Me.cbUser.Text.ToString
        Dim sqlStr As String = "update t_sysparam set param_value='" & classcode & "' where param_name='classcode'"
        If (execSQLQueryNoResult(sqlStr)) Then
            classname = Me.cbclass.Text
        Else
            ErrInfoHandle(m_ModName, funName, "更新classcode出错", sqlStr)
            Exit Sub
        End If
        sqlStr = "update t_sysparam set param_value='" & username & "' where param_name='usercode'"
        If (execSQLQueryNoResult(sqlStr)) Then

        Else
            ErrInfoHandle(m_ModName, funName, "更新username出错", sqlStr)
            Exit Sub
        End If
    End Sub

    Private Sub cbclass_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbclass.SelectedIndexChanged
        Me.cbUser.SelectedIndex = Me.cbclass.SelectedIndex
    End Sub
End Class